class Scdoc < Formula
  desc "Small man page generator"
  homepage "https://sr.ht/~sircmpwn/scdoc/"
  url "https://git.sr.ht/~sircmpwn/scdoc/archive/1.11.4.tar.gz"
  sha256 "e1a9c2000f855123a1a50c8f897073e0ee95fc41787431efe3864c2f1c2e7092"
  license "MIT"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_tahoe:   "c1ba3c08a09b33b58197d9dfde53fda881d4d4444d3396a7e4b63ba1baded7aa"
    sha256 cellar: :any_skip_relocation, arm64_sequoia: "e01b3bbc592393f2a8114835fe070861cfc0698ba04b8ca2267441bd3f4d5716"
    sha256 cellar: :any_skip_relocation, arm64_sonoma:  "8e0388ac90662f8a9551b4fc945f133390e1822b7f288027e906c3937dd9fab9"
    sha256 cellar: :any_skip_relocation, sonoma:        "2e981011c1be208d03d97447d9bfd3451d2fe8925d68a4853527c906481868b6"
    sha256 cellar: :any_skip_relocation, arm64_linux:   "1d8bf46277a5da340b1556cb33cfc56e86564975ff9eccbec7aa3b295861eed3"
    sha256 cellar: :any_skip_relocation, x86_64_linux:  "4f53e0feaf57b9e883533ce5d3ec38beeec40f1073b0fb465abaab100be8132d"
  end

  def install
    # scdoc sets by default LDFLAGS=-static which doesn't work on macos(x)
    system "make", "LDFLAGS=#{ENV.ldflags}", "PREFIX=#{prefix}"
    system "make", "install", "PREFIX=#{prefix}"
  end

  test do
    preamble = <<~EOF
      .\\" Generated by scdoc #{version}
      .\\" Complete documentation for this program is not available as a GNU info page
      .ie \\n(.g .ds Aq \\(aq
      .el       .ds Aq '
      .nh
      .ad l
      .\\" Begin generated content:
    EOF
    assert_equal preamble, pipe_output(bin/"scdoc", "")
  end
end
